<?php


	namespace app\home\controller;


	use app\home\model\Cate;
	use app\home\validate\CategoryValidate;

	class Category extends Base
	{
		public function getCategoryList () {
			$cateModel = new Cate();
			$list = $cateModel->field('id,name')->where(['delete_time' => ['=', 0]])->order('id desc')->select();
			if (!empty($list)) {
				return success($list);
			}

			return error('请联系管理员添加分类');
		}


		public function getGoodsByCategory(){

			$categoryValidate = new CategoryValidate();

			$validateRes = $categoryValidate->goSceneCheck('getGoodsByCategory');

			if($validateRes){
				return error($validateRes);
			}

			$cate_id = intval($this->request->post('cate_id'));
			$cateModel = new Cate();

			$goods_list = $cateModel->with('goods')->field('id,name,image')->where(['id'=>['=',$cate_id]])->find();
			if(!empty($goods_list)){
				return success($goods_list);
			}

			return error('暂无数据');
		}



	}